﻿using System.Linq;
using ExtendedMvc.Tests.Model;
using ExtendedMvc.Tests.Model.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ExtendedMvc.Tests {

	/// <summary>
	///This is a test class for HiddenTest and is intended
	///to contain all HiddenTest Unit Tests
	///</summary>
	[TestClass()]
	public class HiddenTest {

		private static DummyDataSource database;
		private static ModelViewPage<Dummy> view;
		private static ModelViewForm<Dummy> form;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext { get; set; }

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		[ClassInitialize()]
		public static void MyClassInitialize(TestContext testContext) {
			database = new DummyDataSource();
			var dummy = database.Dummies.All().First();
			view = MvcMockHelpers.FakeViewPage("Index", dummy);
			form = new ModelViewForm<Dummy>(view.Html);
		}

		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup() {
		//}
		//
		//Use TestInitialize to run code before running each test
		[TestInitialize()]
		public void MyTestInitialize() {
		}

		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup() {
		//}
		//
		#endregion

		/// <summary>
		///A test for Hidden Constructor
		///</summary>
		[TestMethod()]
		public void Hidden_WIthPropertyName() {
			// Arrange
			var memberName = "BasicProperty";
			var dummy = database.Dummies.All().First();
			var expectedValue = dummy.BasicProperty;
			var expectedOutput = string.Format(@"<input id=""{0}"" type=""hidden"" value=""{1}"" />", memberName, expectedValue);

			// Act
			var hidden = form.Hidden(memberName);
			var output = hidden.ToString();

			// Assert
			Assert.AreEqual<string>(expectedOutput, output);
		}

		/// <summary>
		///A test for StaticText Constructor
		///</summary>
		[TestMethod()]
		public void Hidden_ForModel() {
			// Arrange
			var dummy = database.Dummies.All().First();
			var expectedValue = dummy.BasicProperty;
			var expectedName = "BasicProperty";
			var expectedOutput = string.Format(@"<input id=""{0}"" type=""hidden"" value=""{1}"" />", expectedName, expectedValue);

			// Act
			var hidden = form.Hidden(m => m.BasicProperty);
			var output = hidden.ToString();

			// Assert
			Assert.AreEqual<string>(expectedOutput, output);
		}

		/// <summary>
		///A test for Hidden Constructor
		///</summary>
		[TestMethod()]
		public void Hidden_WithChange() {
			// Arrange
			var dummy = database.Dummies.All().First();
			var expectedValue = dummy.BasicProperty;
			var expectedName = "BasicProperty";
			var onChangeEvent = "return false;";
			var expectedOutput = string.Format(@"<input id=""{0}"" onchange=""{2}"" type=""hidden"" value=""{1}"" />", expectedName, expectedValue, onChangeEvent);

			// Act
			var hidden = form.Hidden(m => m.BasicProperty).OnChange(onChangeEvent);
			var output = hidden.ToString();

			// Assert
			Assert.AreEqual<string>(expectedOutput, output);
		}
	}
}
